// component/coupon-list.js
const config = require('../../config.js');
const request = require('../../utils/request.js')
const utils = require('../../utils/util.js');

import {
    getUseableTicket
} from '../../static/api/api.js'
let app = new getApp()
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        searchParams: Object,
        isShow: Boolean,
    },
    attached: function() {
        let that = this;
        this.getCouponList(this.data.searchParams)
        setTimeout(function() {
            that.setData({
                iscShow: true
            })
        })
    },
    /**
     * 组件的初始数据
     */
    data: {
        couponList: null
    },
    /**
     * 组件的方法列表
     */
    methods: {
        _hideDialog(e) {
            console.log(e)
            let dataset = e.currentTarget.dataset;
            if (dataset.type == "1") {
                this.triggerEvent('closePop', {
                    type: 1
                });
            } else {
                this.triggerEvent('closePop', {
                    type: dataset.type,
                    item: dataset.item
                });
            }

        },
        //获取优惠券信息
        getCouponList(options) {
            let that = this
            this.setData({
                pageLoad:true,
            })
            getUseableTicket(options).then((response) => {
                this.setData({
                    pageLoad: false,
                })
                that.setData({
                    couponList: response.data
                })
            }).catch((response) => {
                this.setData({ 
                    pageLoad: false,
                })
            })
        }
    },

})